﻿using RimWorld;
using Verse;
using Verse.AI;

namespace RimZombieGirl
{
    public class HediffComp_CurseVomit : HediffComp
    {
        private int lastVomitTick = -99999;

        public override void CompPostTick(ref float severityAdjustment)
        {
            base.CompPostTick(ref severityAdjustment);

            Pawn pawn = this.Pawn;
            if (!pawn.RaceProps.Humanlike || !pawn.Spawned || pawn.Dead)
                return;

            if (Find.TickManager.TicksGame % 3000 != 0)
                return;

            if (Find.TickManager.TicksGame - lastVomitTick < 30000)
                return;

            //几率触发呕吐
            if (Rand.Value > 0.1f)
                return;

            //开始呕吐
            if (pawn.jobs != null && pawn.CurJobDef != JobDefOf.Vomit)
            {
                pawn.jobs.StartJob(new Job(JobDefOf.Vomit), JobCondition.InterruptForced, null, resumeCurJobAfterwards: true);
                lastVomitTick = Find.TickManager.TicksGame;

                // 左上角提示
                Messages.Message($"{pawn.LabelShort} 突然呕吐了。".Translate(), pawn, MessageTypeDefOf.NegativeEvent);
            }
        }
    }

    public class HediffCompProperties_CurseVomit : HediffCompProperties
    {
        public HediffCompProperties_CurseVomit()
        {
            this.compClass = typeof(HediffComp_CurseVomit);
        }
    }
}
